<!DOCTYPE html>
<html lang="en">
<head>
    {% load staticfiles %}
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
    <link rel="stylesheet" href="{% static 'css/register.css' %}">

</head>
<body>
<div class="row">
    <div class="col-lg-6 col-lg-offset-3 header">
        <span class="header1">用户登录</span><span class="header2"><a href="{% url 'index' %}">回到首页</a></span>
    </div>
    <div class="col-lg-6 col-lg-offset-3 content">
        <div class="bodyleft"><img src="{% static 'img/register.jpg' %}"></div>
        <div class="bodyright2">
            <form class="form-horizontal" action="#" method="post" autocomplete="off">
                <div class="form-group" style="margin-top: 20px">
                    <label for="inputEmail3" class="col-sm-3 control-label">学号</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="inputEmail3" placeholder="学号" name="studentid">
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputPassword3" class="col-sm-3 control-label">密码</label>
                    <div class="col-sm-9">
                        <input type="password" class="form-control" id="inputPassword3" placeholder="密码" name="password1">
                    </div>
                </div>
                <div class="form-group captcha1">
                    <label for="inputEmail3" class="col-sm-3 control-label">验证码</label>
                    <div class="col-sm-9">
                        {{ login_form.captcha }}
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-9">
                        <button type="button" class="btn btn-default" id="jsLoginBtn">用户登录</button>
                    </div>
                </div>
                <div class="form-group">
                    <span id="errorShow" class="errormsg">

                    </span>
                    <span class="forget"><a href="{% url 'users:sendemail' %}">忘记密码</a></span>
                </div>
                {% csrf_token %}
            </form>
        </div>
    </div>

</div>
<script rel="stylesheet" src="{% static "js/jquery-1.11.1.js" %}"></script>
<script rel="stylesheet" src="{% static "js/login.js" %}"></script>
<script>
    $(function () {
        $("#jsLoginBtn").click(function () {
            $.ajax({
            cache: false,
            url: "{% url 'login' %}",
            data: $("form").serialize(),
            type: "post",
            async: true,
            success: function(data){
                data = JSON.parse(data);
                if (data["status"] == 1){
                     window.location = "/";
                     {#$("#errorShow").html(data["msg"]).show();#}
                }
                else {
                    $("#errorShow").html(data["msg"]).show();
                }
            }
        });
    });
    });
</script>
</body>
</html>